<?php
/**
 * Created by JetBrains PhpStorm.
 * User: admin
 * Date: 18.10.12
 * Time: 21:14
 * To change this template use File | Settings | File Templates.
 */
class User_Model_User extends Mylab_Model
{
    public function __construct($id = null)
    {
        parent::__construct(new User_Model_DbTable_Users(), $id);
    }

    public function authorize($email, $password)
    {
        $auth = Zend_Auth::getInstance();
        $authAdapter = new Zend_Auth_Adapter_DbTable(
            $this->_dbTable->getDefaultAdapter(),
            'users',
            'email',
            'password',
            'md5(?)'
        );
        $authAdapter->setIdentity($email)
            ->setCredential($password);

        $result = $auth->authenticate($authAdapter);
        if ($result->isValid()) {
            $storege = $auth->getStorage();
            $storege->write($authAdapter->getResultRowObject(null, array('password')));
            return true;
        } else {
            return false;
        }
    }
}
